<?php

// Damn it a fuck. We don't check available medias at all: we're only interested in the
// required media. If there's nothing in our records about that stuffy thing you're
// searching for, then, well man, you go on default


if ($definition and file_exists("./".$module->folder."/sections/".$definition[0]) and is_dir("./".$module->folder."/sections/".$definition[0])) {
	$cur_media = array_shift($definition);
} else {
	$cur_media = $site->config[$module->slug.'.media.default'];
}


// WTF?? Why the HELL this file doesn't check the default section???
if ($definition[0]) {
	if (file_exists("./".$module->folder."/sections/".$cur_media."/".$definition[0].".php")) {
		$cur_section = array_shift($definition);
	} else if (file_exists("./".$module->folder."/sections/".$cur_media."/".$site->config[$module->slug.".".$cur_media.".section.default"].".php")) {
		$cur_section = $site->config[$module->slug.".".$cur_media.".section.default"];
	} 
} else {

	// In deed, if there's a definition, a default section and no default file for that section, this is an error, but we won't correct it here and now
	$cur_section = "index";
	
}

function module_theme() {
	global $module, $site, $cur_media;
	echo site_url()."/".$module->folder."/themes/html/".$site->config[$module->slug.'.'.$cur_media.'.theme'];
}
function module_stylesheet() {
	global $module, $site, $cur_media;
	echo site_url()."/".$module->folder."/themes/html/".$site->config[$module->slug.'.'.$cur_media.'.theme']."/style.css";
}

include('sections/'.$cur_media.'/'.$cur_section.'.php');
include('themes/'.$cur_media.'/'.$site->config[$module->slug.".".$cur_media.'.theme'].'/'.$cur_section.'.php');						

?>